import Layout from '@/layouts/BasicLayout.vue'

// 动态导入组件
export const loadView = (view) => {
  if (view === 'Layout') {
    return Layout
  }
  
  // 使用 Vite 支持的动态导入方式
  const modules = import.meta.glob('../views/**/**.vue')
  const componentPath = `../views${view}.vue`
  
  if (modules[componentPath]) {
    return modules[componentPath]
  } else {
    console.error(`找不到组件: ${componentPath}`)
    return () => import('@/views/error/404.vue')
  }
}

// 处理路由数据
export const generateRoutes = (routes) => {
  return routes.map(route => {
    const newRoute = { ...route }
    
    // 处理组件
    if (route.component) {
      newRoute.component = loadView(route.component)
    }
    
    // 处理子路由
    if (route.children && route.children.length) {
      newRoute.children = generateRoutes(route.children)
    }
    
    return newRoute
  })
} 